var sleep_audio=document.getElementById("sleep_audio_iwantsleep");
var morning_audio=document.getElementById('sleep_audio_goodmorning');
var sea_audio=document.getElementById('sleep_audio_sea');
var alarm = false;
var socket = io.connect();
socket.emit('create or join', "123");


$(document).ready(function() {
    $("#submit_alarm").click(function(){
        var timer_time = $("#alarm_timer").val();

        var timer = setInterval(function () {
            morning_audio.play();
            alarm = true;
            try{
                sleep_audio.pause();
                sea_audio.pause();
            }
            catch(err){

            }
            clearInterval(timer);
        }, timer_time * 1000);
    });

    $("#quit_alarm").click(function(){
        try{
            morning_audio.pause();
        }
        catch(err){

        }
        alarm = false;
    });
});
socket.on('temp_illumination', function (data){ //data[0]=온도, data[1]=조도
    console.log(data);
    data = data.split(" ");
    $("#delta_text").text("온도:" + data[0] +" 조도:" + data[1]);
    if(data[1] < 50 && alarm == false) {
        sleep_audio.play();
        if(data[0] > 25) {
            sea_audio.play();
        }
    }
    else {
        sleep_audio.pause();
        sea_audio.pause();
    }

});
